package reduce.fz.com.reduce.service.preference;

import java.util.prefs.PreferencesFactory;

import reduce.fz.com.reduce.bean.User;
import reduce.fz.com.reduce.constant.PreferenceConst;
import reduce.fz.com.reduce.util.base.PreferenceUtil;

/**
 * Created by qingshengzheng on 15/11/9.
 */
public class UserPreference {

    public static void saveUser(User user) {
        PreferenceUtil.saveStringPreference(PreferenceConst.KEY_MOBILE, user.mobile);
        PreferenceUtil.saveStringPreference(PreferenceConst.KEY_PASSWORD, user.password);
        PreferenceUtil.saveStringPreference(PreferenceConst.KEY_NICKNAME, user.nickname);
        PreferenceUtil.saveStringPreference(PreferenceConst.KEY_AVATAR, user.avatar);
        PreferenceUtil.saveLongPreference(PreferenceConst.KEY_UID, user.uid);
    }

    public static void delUser() {
        PreferenceUtil.saveStringPreference(PreferenceConst.KEY_MOBILE, "");
        PreferenceUtil.saveStringPreference(PreferenceConst.KEY_PASSWORD, "");
        PreferenceUtil.saveStringPreference(PreferenceConst.KEY_NICKNAME, "");
        PreferenceUtil.saveStringPreference(PreferenceConst.KEY_AVATAR, "");
        PreferenceUtil.saveLongPreference(PreferenceConst.KEY_UID, 0L);
    }

    public static User getUser() {
        String mobile = PreferenceUtil.getStringPreference(PreferenceConst.KEY_MOBILE);
        String password = PreferenceUtil.getStringPreference(PreferenceConst.KEY_PASSWORD);
        String nickname = PreferenceUtil.getStringPreference(PreferenceConst.KEY_NICKNAME);
        Long uid = PreferenceUtil.getLongPreferences(PreferenceConst.KEY_UID, 0);
        String atatar = PreferenceUtil.getStringPreference(PreferenceConst.KEY_AVATAR);
        User user = new User();
        user.mobile = mobile;
        user.password = password;
        user.nickname = nickname;
        user.avatar = atatar;
        user.uid = uid;
        return user;
    }


}
